package com.zhou.org.controller;

import com.zhou.framework.aop.anotation.LogOption;
import com.zhou.framework.aop.enums.LogLevel;
import com.zhou.framework.model.RS;
import com.zhou.framework.util.BlackListUtil;
import com.zhou.framework.util.SettingUtil;
import com.zhou.org.common.MenuCache;
import com.zhou.org.common.OrgUtil;
import com.zhou.org.common.RightUtil;
import com.zhou.framework.dto.IntegerDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lang.zhou
 * @date 2022/9/5 16:00
 */
@Api(tags = "系统缓存接口")
@RestController
@RequestMapping("/sys/cache")
@Slf4j
public class CacheController {

    @ApiOperation("刷新缓存")
    @LogOption(value = LogLevel.SYSTEM,response = true)
    @PostMapping("/refresh")
    public RS refresh(@RequestBody @Validated IntegerDto dto){
        int id = dto.getId();
        if(id == 1){
            RightUtil.refreshMenuCache();
        }else if(id == 2){
            SettingUtil.refreshCache();
        }else if(id == 3){
            OrgUtil.refreshCache();
        }else if(id == 4){
            MenuCache.reloadMenu();
        }else if(id == 5){
            BlackListUtil.refreshCache();
        }
        return RS.success();
    }
}
